<?php
namespace App\Services\Classes;
use Illuminate\Support\Facades\Cache;

class Youzan
{
    const client_id = '84a8940d18b2dfeaba';
    const client_secret = '4427c3038950f98723965cf836ad5dd9';
    const kdt_id = '43214729';
    const token_cache_key = 'access_token';
    public $token;
    public $access_token;
    
    public function __construct()
    {
        $token = $this->getToken();
        $this->token = $token;
        $this->access_token = $token['access_token'];
    }

    public function orderLists(){
        $method = 'youzan.trades.sold.get'; //要调用的api名称
        $api_version = '4.0.0'; //要调用的api版本号
        $client = new \Youzan\Open\Client($this->access_token);
        $params = [
            'status' => 'WAIT_SELLER_SEND_GOODS',
        ];
        return $client->get($method, $api_version,$params);
    }

    public function reportPayment($params){
        $method = 'youzan.pay.customs.declaration.reportpayment.report';
        $apiVersion = '1.0.1';
        $client = new \Youzan\Open\Client($this->access_token);
        return $client->post($method, $apiVersion,$params);
        
    }
    
    public function updateReportStatus($params){
        $method = 'youzan.pay.customs.declaration.reportpayment.query';
        $apiVersion = '1.0.1';
        $client = new \Youzan\Open\Client($this->access_token);
        return $client->post($method, $apiVersion,$params);
    }

    
    public function queryGoods($params){
        $method = 'youzan.items.custom.get'; //要调用的api名称
        $apiVersion = '3.0.0'; //要调用的api版本号
        $client = new \Youzan\Open\Client($this->access_token);
        $my_params = [
            'item_no' => $params,
        ];
        return $client->post($method, $apiVersion,$my_params);
    }


    private function getToken()
    {
        $clientId = self::client_id;
        $clientSecret = self::client_secret;
        $type = 'silent';
        $keys['kdt_id'] = self::kdt_id;
        return (new \Youzan\Open\Token($clientId, $clientSecret))->getToken($type, $keys);
    }

}
